package net.lovesrc.allin.biz.lbc;

import com.alibaba.fastjson.JSONObject;
import net.lovesrc.allin.Message;
import net.lovesrc.allin.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/lbc")
public class LbcController extends BaseController {

    @Autowired
    private LbcRegisterService lbcRegisterService;

    @Autowired
    private LbcService lbcService;

    @PostMapping("/new-register")
    public Message newRegister(String promotionCode) {
        String newMobile = lbcRegisterService.register(promotionCode);
        return Message.success(newMobile);
    }

    @GetMapping("/list-mine")
    public Message listMine() {
        List<JSONObject> rows = lbcService.listMine();
        return Message.success(rows);
    }

    @PostMapping("/auth-id")
    public Message authId(String mobile) {
        lbcRegisterService.doAuthId(mobile, BaseLbcService.Proxy.PROXY_GELIC);
        return Message.success();
    }

    @PostMapping("/sync-kj")
    public Message syncKj(String mobile) {
        lbcRegisterService.getMyKjs(mobile, BaseLbcService.Proxy.PROXY_GELIC);
        return Message.success();
    }

    @PostMapping("/sync-cp-value")
    public Message syncCPValue(String mobile) {
        lbcService.getCPValue(mobile, BaseLbcService.Proxy.PROXY_GELIC);
        return Message.success();
    }

    @PostMapping("/sync-account")
    public Message syncAccount(String mobile) {
        lbcService.getUserInfo(mobile, BaseLbcService.Proxy.PROXY_GELIC);
        return Message.success();
    }

    @PostMapping("/profit")
    public Message profit(String mobile) {
        lbcService.profitAndSyncData(mobile, BaseLbcService.Proxy.PROXY_GELIC);
        return Message.success();
    }

    @PostMapping("/new-jy")
    public Message newJy(String mobile) {
        lbcService.newSysJy(getCurrentUserId(), mobile, BaseLbcService.Proxy.PROXY_GELIC);
        return Message.success();
    }

    @PostMapping("/pay-jy")
    public Message payJy(String jyId) {
        lbcService.payJyWithAutoJieTu(jyId, BaseLbcService.Proxy.PROXY_GELIC);
        return Message.success();
    }

    @PostMapping("confirm-jy")
    public Message confirmJy(String jyId) {
        lbcService.confirmJy(jyId, BaseLbcService.Proxy.PROXY_GELIC);
        return Message.success();
    }

    @GetMapping("list-buy")
    public Message buyList(String mobile) {
        List<LbcJy> buyJyList = lbcService.getBuyJyList(mobile, BaseLbcService.Proxy.PROXY_GELIC);
        return Message.success(buyJyList);
    }

    @GetMapping("list-buying")
    public Message buyingList(String mobile) {
        List<LbcOrder> buyIngOrders = lbcService.getBuyIngOrders(mobile, BaseLbcService.Proxy.PROXY_GELIC);
        return Message.success(buyIngOrders);
    }

    @PostMapping("/lottery")
    public Message lottery(String mobile) {
        lbcService.lottery(mobile, BaseLbcService.Proxy.PROXY_GELIC);
        return Message.success();
    }
}